<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="empty-box flexWarpCenterColumn" v-if="couponList.length==0">
					<image src="../../static/coupon/empty.png" class="empty-image"></image>
					<view class="empty-tips">这里空空如也！</view>
				</view>
				<view class="coupon-box">
					<view class="coupon-item flexWrapNo" v-for="(item,index) in couponList" :key='index'>
						<view class="left-circular"></view>
						<view class="coupon-left flexWarpCenterColumn">
							<text class="money">{{item.price}}</text>
							<text class="money-tip">面值</text>
						</view>
						<view class="coupon-line"></view>
						<view class="coupon-right flexWarpColumn">
							<text class="coupon-name">{{item.title}}</text>
							<text class="time">有效期：{{item.start_time}}至{{item.end_time}}</text>
						</view>
						<view class="right-circular"></view>
					</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc:0,
				user_id:"",
				couponList:[]
			}
		},
		onReady(){
			setTimeout(() => {
				this.pageOpc=1
			}, 100)
		},
		onLoad(ops) {
			this.user_id=ops.user_id
			this.getCouponlist();
		},
		methods: {
			// 获取优惠券列表
			getCouponlist(){
				this.$request.post(this.$api.memberCoupon, {
					user_id:this.user_id,
					store_id:uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						let newArr=data.list
						for (let i in newArr) {
							newArr[i].start_time=this.$tools.formatDay(newArr[i].start_time*1000)
							newArr[i].end_time=this.$tools.formatDay(newArr[i].end_time*1000)
						}
						this.couponList=newArr
						console.log(this.couponList)
					}
				})
			},
			goIndex(){
				uni.switchTab({
					url:'/pages/home/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		padding-bottom: 100upx;
	}
	.content{
		padding: 0 36upx;
	}
	.verification-box{
		width: 260rpx;
		height: 120rpx;
		margin: 20rpx auto;
	}
	.coupon-box{
		.coupon-item{
			height: 180upx;
			background:#FFE577;
			border-radius: 10upx;
			position: relative;
			margin-bottom: 20upx;
			.left-circular{
				width: 30upx;
				height: 30upx;
				border-radius: 50%;
				background: #040336;
				position: absolute;
				left: -15upx;
			}
			.right-circular{
				width: 30upx;
				height: 30upx;
				border-radius: 50%;
				background: #040336;
				position: absolute;
				right: -15upx;
			}
			.coupon-left{
				width: 224upx;
				.money{
					font-size: 60upx;
					font-family: PingFang SC;
					font-weight: 500;
					line-height: 100upx;
					color: #000000;
				}
				.money-tip{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #000000;
				}
			}
			.coupon-line{
				width: 2upx;
				height: 140upx;
				background: #040336;
			}
			.coupon-right{
				font-size: 24upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 44upx;
				color: #000000;
				margin-left: 32upx;
				.coupon-name{
					font-size: 36upx;
					font-family: PingFang SC;
					font-weight: 600;
					line-height: 50upx;
					color: #000000;
					margin-bottom: 20upx;
				}
			}
		}
	}
	.empty-box{
		margin-bottom: 64upx;
		.empty-image{
			width: 400upx;
			height: 400upx;
		}
		.empty-tips{
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 34upx;
			color: #FFFFFF;
		}
	}
</style>
